<?php
function image_tag_filter($content){
	if(is_Feed()){
		return $content;
	}
	$content = preg_replace_callback(
        "/<img(?:src=[\"'](.*)[\"']|data-caption=[\"'](.*)[\"']|data-slide=[\"'](true|false)?[\"']|alt=[\"'](.*)[\"']|class=[\"'](.*)[\"']|alt=[\"'](.*)[\"']|\s)+\/>/siU",
        "image_tag",
        $content
    );
    
	return $content;
}
function image_tag(&$match) {
	$align = 'center';
	if($match[5] == 'alignleft'){
		$align = 'alignleft';
	}
	elseif($match[5] == 'alignright') {
		$align = 'alignright';
	}
	if($match[3] == 'false'){
		return "<div class=\"$align\">$match[0]</div>";
	}
	$caption = $match[4];
	if($match[2] != ''){
		$caption = $match[2];
	}
	return "<div class=\"$align\"><a href=\"$match[1]\" class=\"highslide\"  onclick=\"return hs.expand(this)\">$match[0]</a>
	<div class=\"highslide-caption\">$caption</div></div>";
}
add_filter('the_content', 'image_tag_filter');

function highslide_js() {
	$js = get_bloginfo('template_url').'/js/highslide/highslide.packed.js';
	$graphicsDir = get_bloginfo('template_url').'/js/highslide/graphics/';
	echo <<<EOF
<script type="text/javascript" src='$js'></script>
<script type="text/javascript">
//<![CDATA[
hs.graphicsDir='$graphicsDir';
hs.showCredits=false;
hs.outlineType='rounded-white';
hs.fadeInOut = true;
hs.registerOverlay({
	html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
	fade: 2,
	position: 'top right'
});
if (hs.addSlideshow) 
hs.addSlideshow({
    interval: 5000,
    repeat: false,
    useControls: true,
    fixedControls: 'fit',
    overlayOptions: {
	    opacity: .6,
	    position: 'bottom center',
	    hideOnMouseOut: true
    }
});
hs.lang={
    loadingText :     '图片加载中...',
    loadingTitle :    '正在加载图片',
    closeText :       '关闭',
    closeTitle :      '关闭',
    moveTitle :       '移动图片',
    moveText :        '移动',
    restoreTitle :    '点击可关闭或拖动',
    fullExpandTitle : '点击查看原图',
    fullExpandText :  '查看原图'
};
hs.Expander.prototype.onMouseOut = function (sender) {
    sender.close();
};
hs.Expander.prototype.onAfterExpand = function (sender) {
    if (!sender.mouseIsOver) 
     	sender.close();
}
//]]>
</script>
EOF;
}
?>
